package org.zs.miracle.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zs.miracle.common.base.dto.BaseLongIdDTO;
import org.zs.miracle.common.base.dto.BaseManyLongIdDTO;
import org.zs.miracle.service.post.IPostService;
import org.zs.miracle.service.post.model.dto.AddPostDTO;
import org.zs.miracle.service.post.model.dto.EditPostDTO;
import org.zs.miracle.service.post.model.dto.PostQueryDTO;
import org.zs.miracle.service.post.model.dto.PostQueryPageDTO;
import org.zs.miracle.service.post.model.vo.PostVO;

;

/**
 * 用户帖子表Controller层,接受处理请求
 */
@Tag(name = "用户帖子接口")
@RestController
@RequestMapping("/post")
@AllArgsConstructor
public class PostController {
  
  @Resource
  IPostService postService;
  
  @Operation(summary = "分页查询", description = "分页查询用户帖子接口}")
  @GetMapping(value = "/pageQueryList", produces = MediaType.APPLICATION_JSON_VALUE)
  @ApiResponse(responseCode = "200", description = "OK")
  
  public Page<PostVO> pageQueryList(PostQueryPageDTO inputDTO) {
    return postService.pageQueryList(inputDTO);
  }
  
  @Operation(summary = "分页条件查询", description = "分页条件查询用户帖子接口}")
  @GetMapping(value = "/pageQuery", produces = MediaType.APPLICATION_JSON_VALUE)
  @ApiResponse(responseCode = "200", description = "OK")
  
  public Page<PostVO> pageQuery(PostQueryDTO inputDTO) {
    return postService.pageQuery(inputDTO);
  }
  
  @Operation(summary = "单个查询", description = "查询用户帖子接口}")
  @GetMapping(value = "/getPost", produces = MediaType.APPLICATION_JSON_VALUE)
  @ApiResponse(responseCode = "200", description = "OK")
  
  public PostVO getOne(@Validated BaseLongIdDTO inputDTO) {
    return postService.getOne(inputDTO);
  }
  
  @Operation(summary = "添加用户帖子", description = "添加用户帖子接口")
  @ApiResponse(responseCode = "200", description = "OK")
  @PostMapping(value = "/addPost", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean addPost(@RequestBody @Validated AddPostDTO inputDTO) {
    return postService.addPost(inputDTO);
  }
  
  @Operation(summary = "删除用户帖子", description = "根据id删除接口")
  @ApiResponse(responseCode = "200", description = "OK")
  @DeleteMapping(value = "/delPost", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean delPost(@RequestBody @Validated BaseManyLongIdDTO inputDTO) {
    return postService.delPost(inputDTO);
  }
  
  @Operation(summary = "编辑用户帖子", description = "编辑用户帖子接口")
  @ApiResponse(responseCode = "200", description = "OK")
  @PatchMapping(value = "/editPost", produces = MediaType.APPLICATION_JSON_VALUE)
  public Boolean addPost(@RequestBody @Validated EditPostDTO inputDTO) {
    return postService.editPost(inputDTO);
  }
}